﻿
       //滚动循环事件的值
        var roll_event;
        //更新滚动数据的事件的值
        var scout_event;
    
        $(document).ready(function(){
 
            if($("#roll").css("display") != "none")
            {
                if(document.getElementById("roll").getElementsByTagName("li").length > 1)
                {
                    startroll();
                    startUpdateScout();
                }
            }
           else
           {
                $("#roll").hide();
                $("#show_hidden_icon").attr("src","/content/images/2/ico-hornx.gif");
           }
            
        });
        
        function startroll()
        {
            $("#roll").textSlider({line:1,speed:500,timer:5000});
            start_roll();
            //roll_event = setInterval(RollScout,5000);
        }
        
        function stoproll()
        {
            stop_roll();
            //clearInterval(roll_event);
        }
        
        function RollScout()
        {
            var li = document.getElementById("roll").getElementsByTagName("li");
            
            var liCount = li.length;
            
            if(liCount <= 1)return;
            
            $(li[0]).slideUp(500,function(){
                var ul = document.getElementById("roll").getElementsByTagName("ul")[0];
                
                var temp = li[0].cloneNode(true);

                ul.appendChild(temp);
                
                ul.removeChild(li[0]);
                
                $(temp).slideDown(1);
            });
           
        }
        
        //显示或隐藏滚动内容
        function showOrHideRoll()
        {
            if($("#roll").css("display") == "none")
            {
                $("#roll").slideDown(500);
                startroll();
                startUpdateScout();
                setCookie("Scout_Open","true");
                $("#show_hidden_icon").attr("src","/content/images/2/ico-horns.gif");
            }
            else
            {
                $("#roll").slideUp(500);
                stoproll();
                stopUpdateScout();
                setCookie("Scout_Open","false");
                $("#show_hidden_icon").attr("src","/content/images/2/ico-hornx.gif");
            }
        }
        
 
        //更新滚动的监视表里的值
        function updateScout()
        {         
            var inputId =  document.getElementById("roll").getElementsByTagName("input");
            if(inputId.length < 1)return;
            
            var id = "";
            for(var i=0;i < inputId.length;i++)
            {
                id += inputId[i].value+"|";
            }
            
            $.getJSON("/securitiesinfo/ajax_getNewFocusPrice",{id:id,t:Math.random()},function(json){

                for(var i=0;i < json["Data"].length;i++)
                {
                    $("#securitiesPrice_"+json["Data"][i].SecuritiesId).html(json["Data"][i].Price);
                    $("#securitiesRate_"+json["Data"][i].SecuritiesId).html(isNaN(json["Data"][i].UpDownRate)?"停牌":json["Data"][i].UpDownRate+"%");
                    
                    if(json["Data"][i].UpDownRate > 0)
                    {
                        document.getElementById("securitiesRate_"+json["Data"][i].SecuritiesId).className ="cc00";
                        document.getElementById("securitiesPrice_"+json["Data"][i].SecuritiesId).className ="cc00";
                    }
                    else if(json["Data"][i].UpDownRate < 0)
                    {
                        document.getElementById("securitiesRate_"+json["Data"][i].SecuritiesId).className = "c080";
                        document.getElementById("securitiesPrice_"+json["Data"][i].SecuritiesId).className = "c080";
                    }
                }
            });
        }
        
        //开始更新监视表数据
        function startUpdateScout()
        {
            scout_event = setInterval(updateScout,30000);
        }
        
        //停止更新监视表数据
        function stopUpdateScout()
        {
            clearInterval(scout_event);
        }
        
     //-------------------------
    // 保存 Cookie 
    function setCookie ( name, value ) 
    { 
        expires = new Date(); 
        expires.setTime(expires.getTime() + (1000 * 86400 * 365)); 
        document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/"; 
    } 

    // 获取 Cookie 
    function getCookie ( name ) 
    { 
        cookie_name = name + "="; 
        cookie_length = document.cookie.length; 
        cookie_begin = 0; 
        while (cookie_begin < cookie_length) 
        { 
        value_begin = cookie_begin + cookie_name.length; 
        if (document.cookie.substring(cookie_begin, value_begin) == cookie_name) 
        { 
        var value_end = document.cookie.indexOf ( ";", value_begin); 
        if (value_end == -1) 
        { 
        value_end = cookie_length; 
        } 
        return unescape(document.cookie.substring(value_begin, value_end)); 
        } 
        cookie_begin = document.cookie.indexOf ( " ", cookie_begin) + 1; 
        if (cookie_begin == 0) 
        { 
        break; 
        } 
        } 
        return null; 
    } 

    // 清除 Cookie 
    function delCookie ( name ) 
    { 
        var expireNow = new Date(); 
        document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/"; 
    } 